﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace Yatagan.Library
{
    public class ObjectCloner
    {
        public static T CloneIt<T>(T ojb)
        {
            T returnObjecect = (T)Convert.ChangeType(CloneIt(ojb), typeof(T));

            return returnObjecect;
        }

        public static object CloneIt(object ojb)
        {
            BinaryFormatter binaryFormatter = new BinaryFormatter();
            MemoryStream ms = new MemoryStream();
            binaryFormatter.Serialize(ms, ojb);
            ms.Position = 0;

            return binaryFormatter.Deserialize(ms);
        }
    }
}
